import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {
    public static void main(String[] args) {
        int [] arr = new int[]{5,4,7,8,6,8,77,8,7,5,4,4};
        insetSort(arr);
        System.out.println(Arrays.toString(arr));

    }
    public static void insetSort(int[] arr){
        int temp = 0;
        for (int i = 1; i < arr.length; i++) {
            int j = i - 1;
            temp = arr[i];
            while(j >= 0 ){
                if(arr[j] > temp){
                    arr[j+1] = arr[j];
                    j--;
                }else {
                    break;
                }
            }
            arr[j+1] = temp;
        }
    }

    /*public static void insetSort(int[] arr){
        int temp = 0;
        for (int i = 1; i < arr.length; i++) {
            temp = arr[i];
            int j = i - 1;
            for(; j >= 0; j--){
                if(arr[j] > temp){
                    arr[j+1] = arr[j];
                }else {
                    break;
                }
            }
            arr[j+1] = temp;
        }
    }*/
}